import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import os
import codecs

seed = 1024
np.random.seed(seed)

path = '../data/'

def get_corpus(corpus_path,corpus_file):
    corpus = []
    for f in corpus_file[0:]:
        try:
            with codecs.open(os.path.join(corpus_path+'/'+f), encoding='gbk') as f:
                corpus.append(f.read())
        except:
            continue
    return corpus

def get_all_data(filename):
    pos_path = path+filename+'/pos'
    neg_path = path+filename+'/neg'

    pos_files = os.listdir(pos_path)
    neg_files = os.listdir(neg_path)

    pos_corpus_1 = get_corpus(pos_path,pos_files)
    neg_corpus_1 = get_corpus(neg_path,neg_files)

    return pos_corpus_1,neg_corpus_1


pd.set_option('display.max_rows', 2000)

def watch_data(corpus,mode='pos'):
    if mode=='pos':
        corpus_ = pd.DataFrame()
        corpus_['pos'] = corpus
    else:
        corpus_ = pd.DataFrame()
        corpus_['neg'] = corpus
    return corpus_


pos_corpus_1,neg_corpus_1 =get_all_data('corpus_1')
pos_corpus_2,neg_corpus_2 = get_all_data('corpus_2')


#watch the data
cor_ = watch_data(pos_corpus_1)
cor_

cor_ = watch_data(neg_corpus_1)
cor_

cor_ =watch_data(pos_corpus_2)
cor_

cor_ = watch_data(neg_corpus_2)
cor_

